package it.gat.client.view;

import it.gat.controller.utils.ImpostazioniDesktop;
import it.gat.controller.utils.WSImpostazioni;

import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JTextField;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.io.IOException;

public class ImpostazioniDialog extends JDialog {

	private final JPanel contentPanel = new JPanel();
	private JTextField txtIndirizzoServer;
	private JTextField txtPorta;

	/**
	 * Create the dialog.
	 */
	public ImpostazioniDialog() {
		setTitle("Impostazioni");
		setBounds(100, 100, 450, 157);
		getContentPane().setLayout(null);
		contentPanel.setBounds(0, 0, 434, 73);
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel);
		contentPanel.setLayout(null);
		{
			JLabel lblPersorsoServer = new JLabel("Indirizzo Server");
			lblPersorsoServer.setBounds(10, 14, 87, 14);
			contentPanel.add(lblPersorsoServer);
		}
		{
			txtIndirizzoServer = new JTextField();
			txtIndirizzoServer.setBounds(93, 11, 312, 20);
			contentPanel.add(txtIndirizzoServer);
			txtIndirizzoServer.setColumns(10);
			txtIndirizzoServer.setText(ImpostazioniDesktop.getProperty(WSImpostazioni.WEBSERVICEURL));
		}
		{
			JLabel lblPorta = new JLabel("Porta");
			lblPorta.setBounds(10, 42, 87, 14);
			contentPanel.add(lblPorta);
		}
		{
			txtPorta = new JTextField();
			txtPorta.setColumns(10);
			txtPorta.setBounds(93, 39, 61, 20);
			txtPorta.setText(ImpostazioniDesktop.getProperty(WSImpostazioni.WEBSERVICEPORT));
			contentPanel.add(txtPorta);
		}
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setBounds(0, 84, 434, 33);
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane);
			{
				JButton okButton = new JButton("OK");
				okButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						ImpostazioniDesktop.setProperty(WSImpostazioni.WEBSERVICEURL, txtIndirizzoServer.getText());
						ImpostazioniDesktop.setProperty(WSImpostazioni.WEBSERVICEPORT, txtPorta.getText());
						try {
							ImpostazioniDesktop.save();
						} catch (IOException e1) {
							// TODO Auto-generated catch block
							e1.printStackTrace();
						}
						dispose();
					}
				});
				okButton.setActionCommand("OK");
				buttonPane.add(okButton);
				getRootPane().setDefaultButton(okButton);
			}
			{
				JButton cancelButton = new JButton("Cancel");
				cancelButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						
						dispose();
					}
				});
				cancelButton.setActionCommand("Cancel");
				buttonPane.add(cancelButton);
			}
		}
	}

}
